package com.teach.flavour.service.impl;

import com.teach.flavour.model.po.FoodsFlavourTag;
import com.teach.flavour.dao.FoodsFlavourTagDao;
import com.teach.flavour.service.MPFoodsFlavourTagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  美食口味表 服务实现类
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-03-04
 */
@Service
public class FoodsFlavourTagServiceImpl extends ServiceImpl<FoodsFlavourTagDao, FoodsFlavourTag> implements MPFoodsFlavourTagService {
    @Autowired
    private FoodsFlavourTagDao foodsFlavourTagDao;
    public List<FoodsFlavourTag> getList(Map<String,Object> param){
        return baseMapper.selectByMap(param);
    }
    @Transactional(rollbackFor = Exception.class)
    public int add(String id,String tagVector){
        String[] split = tagVector.split(",");
        List<String> listId=new ArrayList<>();
        listId.add(foodsFlavourTagDao.getIdByTag("salt_rank",split[0]));
        listId.add(foodsFlavourTagDao.getIdByTag("sour_rank",split[1]));
        listId.add(foodsFlavourTagDao.getIdByTag("spicy_rank",split[2]));
        return foodsFlavourTagDao.addTagByFoodId(id,listId);
    }
}
